package com.kqkj.dyrule.engine.util;

import com.kqkj.dyrule.engine.beans.EventBean;
import com.kqkj.dyrule.engine.beans.EventParam;

import java.util.Set;

public class EventParamComparator {
    /**
     * 比较规则条件和实时事件是否匹配
     * @param param1
     * @param target
     * @return
     */
    public static boolean compare(EventParam param1,EventParam target){
        if(param1.getEventId().equals(target.getEventId())){
            Set<String> keys = param1.getEventProperties().keySet();
            for (String key: keys) {
                String targetValue = target.getEventProperties().get(key);
                if (!param1.getEventProperties().get(key).equals(targetValue)){
                    return false;
                }
            }
            return true;
        }
        return false;
    }

    //重载
    public static boolean compare(EventParam param1, EventBean target){
        if(param1.getEventId().equals(target.getEventId())){
            Set<String> keys = param1.getEventProperties().keySet();
            for (String key: keys) {
                String targetValue = target.getProperties().get(key);
                if (!param1.getEventProperties().get(key).equals(targetValue)){
                    return false;
                }
            }
            return true;
        }
        return false;
    }
}
